package com.usian.controller;

import com.usian.pojo.TbItem;
import com.usian.service.ItemService;
import com.usian.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/service/item")
public class ItemController {
    @Autowired
    private ItemService itemService;

    /**查询商品信息
     * 根据商品id
     * @param itemId
     * @return
     */
    @RequestMapping("/selectItemInfo")
    public TbItem selectItemInfo(Long itemId){
        return this.itemService.selectItemInfo(itemId);
    }

    /**
     * shangxingming
     * 查询商品列表接口
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping("/selectTbItemAllByPage")
    public PageResult selectTbItemAllByPage(Integer page, Integer rows){
        return itemService.selectTbItemAllByPage(page,rows);
    }

    /**
     * 冯果果
     * 根据Id删除商品
     * @param itemId
     */
    @RequestMapping(value = "deleteByPrimaryKey", method = RequestMethod.POST)
    public int deleteByPrimaryKey(@RequestParam("itemId") Long itemId){
        return itemService.deleteByPrimaryKey(itemId);
    }

    /**
     * liurui
     * 商品添加接口
     * @param tbItem
     * @param desc
     * @param itemParams
     * @return
     */
    @RequestMapping("/insertTbItem")
    public Integer insertTbItem(@RequestBody TbItem tbItem, String desc,
                                String itemParams){
        return this.itemService.insertTbItem(tbItem,desc,itemParams);
    }

    /**
     * 薛丁豪22.03.24
     * 修改商品信息地址
     * 回显
     * @param itemId
     * @return
     */
    @RequestMapping("/preUpdateItem")
    public Map<String,Object> preUpdateItem(Long itemId){
        return this.itemService.preUpdateItem(itemId);
    }
    /**
     * 薛丁豪22.03.24
     * 修改商品信息地址
     * 修改的保存
     * @param tbItem
     * @param desc
     * @param itemParams
     * @return
     */
    @RequestMapping("/updateTbItem")
    public void updateTbItem(@RequestBody TbItem tbItem,String desc,String itemParams){
        this.itemService.updateTbItem(tbItem,desc,itemParams);
    }

}